import pygame, sys, math, time
pygame.init()

from Ball import Ball
from PlayerBall import PlayerBall



width = 900
height = 492
size = width, height

screen = pygame.display.set_mode(size)

bgImage = pygame.image.load("tokyo.png")
bgRect = bgImage.get_rect()

stime = time.time()


        

clk = pygame.time.Clock()  
changed = False


ball1 = Ball("kingkong.png", [4,4], [150,150], [100,300])
ball2 = Ball("mothera.png", [4,4], [150,150], [300,400])
ball3 = Ball("King Ghidorah.png", [4,4], [150,150], [400,200])
ball4 = Ball("rodan.png", [4,4], [150,150], [100,150])
ball5 = Ball("mechgodzilla.png", [4,4], [150,150], [600,300])
ballp = PlayerBall(["godzilla.png"] ,[4,4], [150,150], [800,100])

while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit()
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_d or event.key == pygame.K_RIGHT:
                ballp.direction("right")
            if event.key == pygame.K_a or event.key == pygame.K_LEFT:
                ballp.direction("left")
            if event.key == pygame.K_w or event.key == pygame.K_UP:
                ballp.direction("up")
            if event.key == pygame.K_s or event.key == pygame.K_DOWN:
                ballp.direction("down")
        if event.type == pygame.KEYUP:
            if event.key == pygame.K_d or event.key == pygame.K_RIGHT:
                ballp.direction("stop right")
            if event.key == pygame.K_a or event.key == pygame.K_LEFT:
                ballp.direction("stop left")
            if event.key == pygame.K_w or event.key == pygame.K_UP:
                ballp.direction("stop up")
            if event.key == pygame.K_s or event.key == pygame.K_DOWN:
                ballp.direction("stop down")
    
    ctime = time.time() - stime

    if ctime >= 10 and not changed:
        bgImage = pygame.image.load("city_dest.png")
        changed = True
    
    ball1.update()
    ball2.update()
    ball3.update()
    ball4.update()
    ball5.update()
    ballp.update()
    
    ball1.collideWall(width, height)
    ball2.collideWall(width, height)
    ball3.collideWall(width, height)
    ball4.collideWall(width, height)   
    ball5.collideWall(width, height)
    ballp.collideWall(width, height)
    
    ball1.collideBall(ball2)
    ball1.collideBall(ball3)
    ball2.collideBall(ball3)
    
    ball3.collideBall(ball4)
    ball3.collideBall(ball5)
    ball4.collideBall(ball5)
    
    ball1.collideBall(ball4)
    ball1.collideBall(ball5)
    ball2.collideBall(ball4)
    ball2.collideBall(ball5)
   
    
    
    
    
    ballp.collideBall(ball1)
    ballp.collideBall(ball2)
    ballp.collideBall(ball3)
    ballp.collideBall(ball4)
    ballp.collideBall(ball5)
    
    screen.blit(bgImage, bgRect)
    
 
    screen.blit(ball1.image, ball1.rect)
    screen.blit(ball2.image, ball2.rect)
    screen.blit(ball3.image, ball3.rect)
    screen.blit(ball4.image, ball4.rect)
    screen.blit(ball5.image, ball5.rect)
    screen.blit(ballp.image, ballp.rect)
    pygame.display.flip()
    
    clk.tick(60)

    

    
    
    

    
    
    
    
    
    
    